package com.emr.web.controller.emr;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.emr.common.annotation.Log;
import com.emr.common.enums.BusinessType;
import com.emr.module.domain.Yizhu;
import com.emr.module.service.IPersonalService;
import com.emr.module.service.IYizhuService;
import com.emr.web.core.base.BaseController;
import com.emr.framework.web.page.TableDataInfo;
import com.emr.common.base.AjaxResult;

/**
 * 医嘱 信息操作处理
 * 
 * @author emr
 * @date 2019-02-21
 */
@Controller
@RequestMapping("/module/yizhu")
public class YizhuController extends BaseController
{
    private String prefix = "module/yizhu";
	
	@Autowired
	private IYizhuService yizhuService;
	
	@Autowired
	private IPersonalService ipersonalService ;
	@RequiresPermissions("module:yizhu:view")
	@GetMapping()
	public String yizhu()
	{
	    return prefix + "/yizhu";
	}
	
	/**
	 * 查询医嘱列表
	 */
	@RequiresPermissions("module:yizhu:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Yizhu yizhu)
	{
		startPage();
		if("".equals(yizhu.getBingName())){
			yizhu.setBingName(null);
		}
        List<Yizhu> list = yizhuService.selectYizhuList(yizhu);
		return getDataTable(list);
	}
	
	/**
	 * 新增医嘱
	 */
	@GetMapping("/add")
	public String add(ModelMap mmap)
	{
		mmap.put("posts",ipersonalService.selectIcdAll());
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存医嘱
	 */
	@RequiresPermissions("module:yizhu:add")
	@Log(title = "医嘱", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Yizhu yizhu)
	{		
		return toAjax(yizhuService.insertYizhu(yizhu));
	}

	/**
	 * 修改医嘱
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Yizhu yizhu = yizhuService.selectYizhuById(id);
		mmap.put("posts", ipersonalService.selectUPersonalByIds(yizhu.getPersonalId()));
		mmap.put("yizhu", yizhu);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存医嘱
	 */
	@RequiresPermissions("module:yizhu:edit")
	@Log(title = "医嘱", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Yizhu yizhu)
	{		
		return toAjax(yizhuService.updateYizhu(yizhu));
	}
	
	/**
	 * 删除医嘱
	 */
	@RequiresPermissions("module:yizhu:remove")
	@Log(title = "医嘱", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(yizhuService.deleteYizhuByIds(ids));
	}
	
}
